package com;


import com.basic.common.security.Md5DsUtil;

import java.io.InputStream;
import java.math.BigInteger;
import java.net.URL;
import java.security.MessageDigest;

/**
 * 勿删，用于系统常量值的生成
 *
 * @author
 * @date
 */
public class SystemMain {
    /**
     * 校验apk的sha-1值
     *
     * @return
     */
    public static String checkApkDigest(String apkPath) {
        try {
            MessageDigest msgDigest = MessageDigest.getInstance("SHA-1");
            byte[] bytes = new byte[1024];

            int byteCount;
            URL url = new URL(apkPath);
            InputStream fis = url.openConnection().getInputStream();
            while ((byteCount = fis.read(bytes)) > 0) {
                msgDigest.update(bytes, 0, byteCount);
            }
            BigInteger bi = new BigInteger(1, msgDigest.digest());
            String sha = bi.toString(16);
            fis.close();
            return sha;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static final void main(String[] args) {
        String appToken = Md5DsUtil.md5("DEMOX" + 0);
        System.out.println("APP-Token:" + appToken);
        String sysToken = Md5DsUtil.md5("demox.nxin.com");
        System.out.println("系统校验码：" + sysToken.toUpperCase());

//        System.out.println("安卓安装包验密串：" +  checkApkDigest("http://x-res.nxin.com/potato_release_v1.0.0_2019-11-13-19-01-52.apk"));
    }
}
